<template>
    <div class="">
      <div class="avatar-info-box">
        <el-button type="text" @click="dialogVisible = true" class="">
          <div class="avatar-info-pic"></div>
          <p>点击头像更换</p>
        </el-button>
      </div>




      <el-dialog title="提示" v-model="dialogVisible" size="tiny">
        <!-- avatar pic upload -->
        <el-upload
          class="avatar-uploader"
          v-loading.fullscreen.lock="fullscreenLoading"
          action="http://192.168.2.162:8080/TeachingMIS/baseInfoCommon/uploadPhoto"
          name="photo"
          :on-progress="uploading"
          :show-file-list="false"
          :on-success="handleAvatarScucess"
          :before-upload="beforeAvatarUpload">
          <img v-if="imageUrl" :src="imageUrl" class="avatar">
          <i v-else class="el-icon-plus avatar-uploader-icon"></i>
        </el-upload>
        <!-- upload end  -->


        <!-- 文件上传确定之后 提示正在上传 -->
        <span slot="footer" class="dialog-footer">
          <el-button @click="dialogVisible = false">取 消</el-button>
          <el-button type="primary" @click="">确 定</el-button>
        </span>
      </el-dialog>


    </div>
</template>
<style>

</style>
<script>

    export default{
        name : '',
        data(){
            return{
                fullscreenLoading:false,
                dialogVisible: false,
                imageUrl: ''
            }
        },
        components:{

        },
        methods: {
        //
          handleAvatarScucess(res, file) {
            this.fullscreenLoading = false;
            console.log(res);
            this.imageUrl = URL.createObjectURL(file.raw);
          },
          beforeAvatarUpload(file) {
            const isJPG = file.type === 'image/jpeg';
            const isLt2M = file.size / 1024 / 1024 < 2;

            if (!isJPG) {
              this.$message.error('上传头像图片只能是 JPG 格式!');
            }
            if (!isLt2M) {
              this.$message.error('上传头像图片大小不能超过 2MB!');
            }
            return isJPG && isLt2M;
          },
          //upload
          uploading:function(){
            this.fullscreenLoading = true;
          }

        },
    }
</script>
